package net.esj.basic.utils;

import java.util.Map;

import net.esj.basic.utils.Validators;

import org.apache.struts2.util.StrutsTypeConverter;

public class FloatConverter extends StrutsTypeConverter {
    @Override  
    public Object convertFromString(Map context, String[] values, Class toClass) { 
    	String floatString = null; 
    	
    	if(null == values) return null;
    	if(values.length > 0) {
    		floatString = values[0];
    		if (Validators.isEmpty(floatString)) {
    			return 0f;
    		}
    	}
    	
    	return Float.valueOf(floatString);
    }  
  
    @Override  
    public String convertToString(Map context, Object o) {  
    	if (o instanceof Float) {  
    		return ((Float)o).toString();
    	}  
    	return ""; 
    }  

}